package com.github.niefy.config;

import com.github.niefy.modules.openapi.resource.filter.OpenAccessTokenInterceptor;
import com.github.niefy.modules.third.filter.AccessLimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : [86188]
 * @description : 拦截器配置
 * @createTime : [2023/5/16 9:19]
 * @updateUser : [86188]
 * @updateTime : [2023/5/16 9:19]
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    OpenAccessTokenInterceptor openAccessTokenInterceptor;
    @Autowired
    AccessLimitInterceptor accessLimitInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] openApiPath = {"/openapi/api/*"};
        String[] accessLimitPath = {"/third/**"};
        String[] accessLimitExcludePath = {"/third/thirdUser/getThirdToken"};
        registry.addInterceptor(openAccessTokenInterceptor)
                .addPathPatterns(openApiPath);
        registry.addInterceptor(accessLimitInterceptor)
                .addPathPatterns(accessLimitPath)
                .excludePathPatterns(accessLimitExcludePath);
    }
}
